﻿/**
Library: Alternative Transitioning
Author: Valentyn Derkach 2007.07.04
———————————————————————————————————————————————————————————————————————————————————————————————————————————————————
This is a simple tween processor class. It uses a change factor to calculate a new value based on the 
current and final values. The equation is 
	newValue = currentValue + changeFactor*(endValue - currentValue)
/**/

package com.bizmlib.transitioning
{

	import com.bizmlib.transitioning.ITweenProcessor;


	public class TweenProcessorSimple extends Object implements ITweenProcessor
	{
		
		public var changeFactor:Number = 1;
		public var minLimit:Number = 1;
		private var maxDValue:Number = 0;
		
		
		public function TweenProcessorSimple(changeFactor:Number, minLimit:Number){
			if(!isNaN(changeFactor)){this.changeFactor = changeFactor;}
			if(!isNaN(minLimit)){this.minLimit = minLimit;}
		}
		
		public function reInit():void{}
		
		public function onBeforeIteration():void
		{
			maxDValue = 0;
		}
		
		public function performCalculation(propertyName:String, currentValue:Number, endValue:Number):Number
		{
			//trace(this + ".performCalculation(" + arguments + ")");
			
			var newValue:Number = (Math.abs(currentValue-endValue)<=minLimit) ? endValue : currentValue+(endValue-currentValue)*changeFactor;
			maxDValue = Math.max(maxDValue, Math.abs(newValue - endValue));
			return newValue;
		}
		
		public function isFinal():Boolean
		{
			if(maxDValue == 0)
			{
				return true;
			}
			return false;
		}

		public function onAfterIteration():void
		{
		}

		public function toString():String{
			return("[TweenProcessorSimple: changeFactor=" + changeFactor + "]");
		}
	}
}